package villa.tools.mq.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

class ToolBarApp{
	ToolBar bar = null;
	TabFolder tab = null;
	public void setLayout(FormData formData)
	{
		this.bar.setLayoutData(formData);
	}
	
	public ToolBar getToolBar()
	{
		return this.bar;
	}
	
	public void setTab(TabFolder tab)
	{
		this.tab = tab;
	}
	
	
	public ToolBarApp(Composite parent, Display d) {
		try {
			
			//this.basic = basic;
			bar = new ToolBar(parent,SWT.HORIZONTAL);
	        
	        final Image getQMAction = new Image(d, "icons/getwsdl.gif");
	        final Image putQMAction = new Image(d, "icons/resume_co.gif");
	        final Image indentAction = new Image(d, "icons/indent.gif");
	        final Image escapeXMLAction = new Image(d, "icons/escapexml.gif");
	        final Image unescapeXMLAction = new Image(d, "icons/unescapexml.gif");
	        final Image newAction = new Image(d, "icons/add.gif");
	        final Image saveAction = new Image(d, "icons/saveall_edit.gif");
	        final Image closeAction = new Image(d, "icons/delete_edit.gif");
	        final Image indentToggleAction = new Image(d, "icons/toggleindent.gif");
	        final Image wrapToggleAction = new Image(d, "icons/wrap.gif");
	        
	        final ToolItem getQMActionItem = new ToolItem(bar, SWT.PUSH);
	        getQMActionItem.setImage(getQMAction);
	        getQMActionItem.setText("getQMAction");
	        getQMActionItem.setToolTipText("getQMAction");
	        
	        final ToolItem putQMActionItem = new ToolItem(bar, SWT.PUSH);
	        putQMActionItem.setImage(putQMAction);
	        putQMActionItem.setText("putQMAction");
	        putQMActionItem.setToolTipText("putQMAction");
	        
	        final ToolItem indentActionItem = new ToolItem(bar, SWT.PUSH);
	        indentActionItem.setImage(indentAction);
	        indentActionItem.setText("indentAction");
	        indentActionItem.setToolTipText("indentAction");
	        
	        final ToolItem escapeXMLActionItem = new ToolItem(bar, SWT.PUSH);
	        escapeXMLActionItem.setImage(escapeXMLAction);
	        escapeXMLActionItem.setText("escapeXMLAction");
	        escapeXMLActionItem.setToolTipText("escapeXMLAction");
	        
	        final ToolItem unescapeXMLActionItem = new ToolItem(bar, SWT.PUSH);
	        unescapeXMLActionItem.setImage(unescapeXMLAction);
	        unescapeXMLActionItem.setText("unescapeXMLAction");
	        unescapeXMLActionItem.setToolTipText("unescapeXMLAction");
	        
	        final ToolItem newActionItem = new ToolItem(bar, SWT.PUSH);
	        newActionItem.setImage(newAction);
	        newActionItem.setText("newAction");
	        newActionItem.setToolTipText("newAction");
	        
	        final ToolItem saveActionItem = new ToolItem(bar, SWT.PUSH);
	        saveActionItem.setImage(saveAction);
	        saveActionItem.setText("saveAction");
	        saveActionItem.setToolTipText("saveAction");
	        
	        final ToolItem closeActionItem = new ToolItem(bar, SWT.PUSH);
	        closeActionItem.setImage(closeAction);
	        closeActionItem.setText("closeAction");
	        closeActionItem.setToolTipText("closeAction");
	        
	        final ToolItem indentToggleActionItem = new ToolItem(bar, SWT.PUSH);
	        indentToggleActionItem.setImage(indentToggleAction);
	        indentToggleActionItem.setText("indentToggleAction");
	        indentToggleActionItem.setToolTipText("indentToggleAction");
	        
	        final ToolItem wrapToggleActionItem = new ToolItem(bar, SWT.PUSH);
	        wrapToggleActionItem.setImage(wrapToggleAction);
	        wrapToggleActionItem.setText("wrapToggleAction");
	        wrapToggleActionItem.setToolTipText("wrapToggleAction");
	        
	        getQMActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	                Actions.getQMActionF(tab);
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
	        putQMActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	            	Actions.putQMActionF(tab);
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
	        indentActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	                Actions.indentActionF(tab);
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
	        escapeXMLActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	                Actions.escapeXMLActionF(tab);
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
	        unescapeXMLActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	                Actions.unescapeXMLActionF(tab);
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
	        newActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	            	if (tab.getItemCount() == 0) {
	            		closeActionItem.setEnabled(true);
	            		putQMActionItem.setEnabled(true);
	            		getQMActionItem.setEnabled(true);
	            		
	            	}
	            	Actions.newActionF(tab);
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
	        saveActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	                Actions.saveActionF(tab);
	            	//saveActionItem.setEnabled(false);
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
	        closeActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	                
	                Actions.closeActionF(tab);
	            	if (tab.getItemCount() == 0) {
						closeActionItem.setEnabled(false);
						putQMActionItem.setEnabled(false);
						getQMActionItem.setEnabled(false);
					}
					
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
	        indentToggleActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	            	boolean val = Basic.getInstancia().getIndent();
	            	Actions.indentToggleActionF(!val);
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
	        wrapToggleActionItem.addSelectionListener(new SelectionListener() {
	            public void widgetSelected(SelectionEvent e) {
	            	boolean val = Basic.getInstancia().getWrap();
	            	Actions.wrapToggleActionF(val);
	                
	            }
	            public void widgetDefaultSelected(SelectionEvent e) {                
	           }
	           });
		    
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

